//index.js
//获取应用实例
const app = getApp()
const API = require('../../utils/api');
Page({
  data: {
    books:[],
    endflag:false,
    hotBooks:[]
  },
  onPageScroll: function (e) {
    console.log(e.scrollTop)
  },
  onReady: function () {
  },
  getDetails:function(e){
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../details/index?id=' + id,
    })
  },
  search:function(e){
    console.log(e)
    if(e.detail.value != ''){
      API.getSearch({
        "key":e.detail.value
      }).then(resp=>{
        if(resp.length != 0 ){
          this.setData({
            books:resp,
            endflag:true
          })
        }else{
          this.setData({
            books:resp,
            endflag:false
          })
        }
      })
    }else{
      this.setData({
        books:[],
        endflag:false
      })
    }
    
  },
  onLoad: function () {
    API.getrecbook().then(resp=>{
      this.setData({
        hotBooks:resp
      })
    })
  },
})
